#include <iostream>
using namespace std;

//https://www.nowcoder.com/practice/1718131e719746e9a56fb29c40cc8f95?tpId=230&tqId=39753&ru=/exam/oj

const int N = 2e5 + 10;

int n;
int dp[N];
int arr[N];

int main()
{
    cin >> n;

    for (int i = 1; i <= n; i++) cin >> arr[i];

    int ret = -0x3f3f3f3f;
    for (int i = 1; i <= n; i++)
    {
        dp[i] = max(dp[i - 1], 0) + arr[i];
        ret = max(ret, dp[i]);
    }

    cout << ret << endl;

    return 0;
}
